package com.yijiajiao.finance.bean;

import java.util.ArrayList;
import java.util.List;

/**
 * @AUTHOR zhaoming@eduspace
 * @CREATE 2017-02-20-13:27
 */
public class Page<T> {

    private static final int DEF_COUNT = 20;

    private int pageNo = 1;
    private int pageSize = 20;
    private int total = 0;
    private List<T> list = new ArrayList<>();

    public Page() {
    }

    public Page(int pageNo, int pageSize,int total, List<T> list) {
        setPageNo(pageNo);
        setPageSize(pageSize);
        setTotal(total);
        this.list = list;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        if (pageNo<=0){
            this.pageNo = 1;
        }else {
            this.pageNo = pageNo;
        }
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        if (pageSize<=0){
            this.pageSize = DEF_COUNT;
        }else {
            this.pageSize = pageSize;
        }
    }

    public int getPages() {
        return this.total/this.pageSize+1;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        if (total <0 ){
            this.total = 0;
        }else {
            this.total = total;
        }
    }
}
